<?php
class Account
{
	public $Table="jlaccount";
	public $accountid;
	public $accountname;
	public $jobposting;
	public $resumespermonth;
	public $price;
	public $position;
	
	function loadByKey($id)
	{
		$ob=new ClassConnect();
		$sql="select * from `".$this->Table."` where accountid='".$id."'";
		$row=$ob->singleData($sql);
		
		if(count($row)>1)
		{
			foreach($row as $key =>$item)
				$this->$key = $item;
		}
		
		
	}
	
	function loadByItem($data)
	{
		foreach($data as $key =>$item)
			$this->$key = $item;
	}
	
	function getTable($dk="")
	{
		$ob=new ClassConnect();
		$sql="select * from `".$this->Table."` where 1=1 $dk";
		$data=$ob->mutiData($sql);
		return $data;
	}
	
	function getNextPos($cjobposting)
	{
		$ob=new ClassConnect();
		$sql="SELECT max(position) as max FROM `jlaccount`";
		$row=$ob->singleData($sql);
		$max=$row['max'];
		return $max + 1;
	}
	
	function save($conn)
	{
		$ob=new ClassConnect();
		$obj = new Account();
		$field=array(
						"accountid",
						"accountname",
						"jobposting",
						"resumespermonth",
						"price",
						"position"
						
					);
		$value=array(
						$this->accountid,
						$this->accountname,
						$this->jobposting,
						$this->resumespermonth,
						$this->price,
						$this->position
			
					);
		$obj->loadByKey($this->accountid);
		if($obj->accountid =="")
		{
			
			return $ob->insertData($conn,$this->Table,$field,$value);
		}
		else
		{
			$where="accountid = '".$this->accountid."'";
			return $ob->updateData($conn,$this->Table,$field,$value,$where);
		}
	}
	
	
	function delete($conn)
	{
		$ob=new ClassConnect();	
		$where="accountid = '".$this->accountid."'";
		return $ob->deleteData($conn,$this->Table,$where);
			
	}
	
}
?>
